package com.scenery;

import java.util.ArrayList;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.Toast;

import com.scenery.services.SceneryServices;
import com.scenery.services.SetManager;
import com.scenery.util.Loger;
import com.scenery.view.SceneryListView;
import com.scenery.vo.Scenery;
/***
 * 景点列表
 * */
public class SceneryActivity extends Activity {
	/**
	 * @see android.app.Activity#onCreate(Bundle)
	 */
	String tag=SceneryActivity.class.getName();
	SceneryListView sceneryListView;
	ArrayList<Scenery> sceneryList;
	Button btnMap;
	SetManager setmanager;
	SceneryServices scsevice;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// TODO Put your code here
		 setContentView(R.layout.scenery_list);
		 sceneryListView=(SceneryListView) findViewById(R.id.sceneryList);
		 btnMap=(Button) findViewById(R.id.btnMap);
		 setmanager=new SetManager(SceneryActivity.this);
		 scsevice=new SceneryServices(setmanager.getIp(),"8080",SceneryActivity.this);
		 sceneryListView.setOnItemClickListener(new OnItemClickListener(){

				@Override
				public void onItemClick(AdapterView<?> arg0, View arg1, int poit,
						long arg3) {
					// TODO Auto-generated method stub
					
						Intent it=new Intent();
						Bundle bundle = new Bundle();
						bundle.putParcelable("bean", sceneryList.get(poit));
						it.putExtras(bundle);
						it.setClass(SceneryActivity.this, SceneryInfoActivity.class);
						startActivity(it);
					
					
				}

				
				
			});
		 btnMap.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent it=new Intent();
				Bundle bundle = new Bundle();
				bundle.putParcelableArrayList("list", sceneryList);
				it.putExtras(bundle);
				it.setClass(SceneryActivity.this, PoiSearch.class);
				startActivity(it);
			}
		});
		 new LoginAsyncTask().execute(0);
	}
	class LoginAsyncTask extends AsyncTask<Integer,Integer,Integer>{
		int type;//
		ProgressDialog dialog=new ProgressDialog(SceneryActivity.this);
		
		
		@Override
		protected Integer doInBackground(Integer... params) {
			// TODO Auto-generated method stub
			//return UserServices.login(user, pwd);
			
			sceneryList=scsevice.getSceneryList("133");
		
			Loger.d(tag, sceneryList.toArray().toString());
			return 0;
		}
		@Override
		protected void onPreExecute() {
			// TODO Auto-generated method stub
			super.onPreExecute();
			dialog.setMessage("加载数据中");
			dialog.show();
		}
		@Override
		protected void onPostExecute(Integer result) 
		{
			
			Log.d(tag, "onPostExecute:"+result);
			dialog.dismiss();
			Toast.makeText(SceneryActivity.this, "成功", Toast.LENGTH_LONG).show();
			sceneryListView.refresh(sceneryList);

		}
		
	};
}
